package com.xbongbong.pro.enums.raiders.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 价值攻略操作按钮枚举
 * @author zcp
 * @version v1.0
 * @date 19/9/19 019 14:31
 * @update 19/9/19 019 14:31
 * @since v1.0
 */
@Getter
public enum RaidersOperateEnum {
    /**
     * 操作枚举
     */
    EDIT(1,"edit", "enum.raidersOperate.name.edit"),


    DELETE(2,"delete", "enum.raidersOperate.name.delete"),


    PUBLISH(3,"publish", "enum.raidersOperate.name.publish"),


    UN_PUBLISH(4,"unPublish", "enum.raidersOperate.name.un_publish"),


    VIEW(5,"view", "enum.raidersOperate.name.view"),


    UNKNOWN(404,"", "enum.raidersOperate.name.unknown"),

    ;

    /**
     * 枚举值 --
     */
    private final int code;
    /**
     * 枚举信息--中文名称
     */
    private final String alias;
    /**
     * 枚举信息--中文名称
     */
    private final String name;

    RaidersOperateEnum(int code, String alias, String name) {
        this.code = code;
        this.alias = alias;
        this.name = name;
    }
    
    /**
     * 通过alias得到操作枚举
     * @param alias
     * @param defaultEnum 默认操作
     * @return com.xbongbong.pro.enums.raiders.enums.RaidersOperateEnum
     * @author zcp
     * @date 19/11/8 008 15:29
     * @update 19/11/8 008 15:29
     * @since v1.0
     * @version v1.0
     */
    public static RaidersOperateEnum getByAlias(String alias, RaidersOperateEnum defaultEnum) {
        if (alias == null || Objects.equals(alias, "")) {
            return defaultEnum;
        }
        for (RaidersOperateEnum cache : values()) {
            if (Objects.equals(cache.alias, alias)) {
                return cache;
            }
        }
        return defaultEnum;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
